package qimao.com.edu.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import qimao.com.edu.dao.AuthorDao;
import qimao.com.edu.dao.impl.AuthorDaoImpl;
import qimao.com.edu.entity.Author;
import qimao.com.edu.service.AuthorService;

public class AuthorServiceImpl implements AuthorService {

	AuthorDao autDao = new AuthorDaoImpl();
	@Override
	public int registerAuthorInfo(Author authorInfo) {
		Author author = null;
		Author a1 = autDao.selectWriterByName(authorInfo);
		Author a2 = autDao.selectWriterByPenName(authorInfo);
		if(a1 == null && a2 == null) {
			return autDao.insWriter(authorInfo);
		} 
		return autDao.insWriter(authorInfo);
	}
	@Override
	public Map<String, Object> authorLogin(Author author) {
		Map<String,Object> map = new HashMap();
		Author loginAuthor = autDao.selectAuthor(author);
		
		if(loginAuthor != null) {
			map.put("loginAuthor",loginAuthor);
		}else {
			loginAuthor = autDao.selectWriterByName(author);
			if(loginAuthor == null) {
				map.put("msg","用户名不存在");
			}else {
				map.put("msg","密码错误");
			}
		}
		return map;
	}
	@Override
	public int deleteAuthorById(Integer author_id) {
		return autDao.deleteAuthorById(author_id);
	}
	@Override
	public Author AuthorByAuthorId(Integer author_id) {
		// TODO Auto-generated method stub
		return autDao.AuthorByAuthorId(author_id);
	}
	@Override
	public int updateWorksCount(Integer author_id, int works_count) {
		// TODO Auto-generated method stub
		return autDao.updateWorksCount(author_id, works_count);
	}
	@Override
	public int updateAuthorBio(Integer author_id, String bio) {
		// TODO Auto-generated method stub
		return autDao.updateAuthorBio(author_id, bio);
	}
	@Override
	public int updatePenName(Integer author_id, String pen_name) {
		// TODO Auto-generated method stub
		return autDao.updatePenName(author_id, pen_name);
	}
	@Override
	public int updateAuthorStatus(Integer author_id, Integer status) {
		// TODO Auto-generated method stub
		return autDao.updateAuthorStatus(author_id, status);
	}
	@Override
	public List<Author> AllAuthor() {
		// TODO Auto-generated method stub
		return autDao.AllAuthor();
	}
	@Override
	public int updateAuthor(Author author) {
		// TODO Auto-generated method stub
		return autDao.updateAuthor(author);
	}
}
